//
//  MXAddStepController.m
//  HNBaseProject
//
//  Created by xujie on 2024/6/3.
//

#import "MXAddStepController.h"
#import "MxPublicNav.h"
#import "MXAddSetWifiController.h"
@interface MXAddStepController () <MxNavigationViewDelegate>
@property (nonatomic, strong) MxPublicNav *nav;
@property (nonatomic, strong) UILabel *nextLab;
@property (nonatomic, strong) UIImageView *sureImageV;
@property (nonatomic, assign) BOOL select;
@end

@implementation MXAddStepController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createUI];
}

- (void)createUI {
    
    self.nav = [[MxPublicNav alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kNavBarHeight)];
    self.nav.delegate = self;
    [self.view addSubview:self.nav];
    
    UILabel *addLab = [[UILabel alloc] initWithFrame:CGRectMake(17, CGRectGetMaxY(self.nav.frame), 200, 30)];
    [self.view addSubview:addLab];
    addLab.text = @"添加设备";
    addLab.textColor = [UIColor colorWithHexString:@"#221815"];
    addLab.font = PFRFontMedium(30);
    
    UIImageView *noticeIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"add_notice_icon"]];
    [self.view addSubview:noticeIcon];
    [noticeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.width.mas_equalTo(260);
        make.height.mas_equalTo(221);
        make.top.mas_equalTo(addLab.mas_bottom).offset(74);
    }];
    
    UILabel *setLab = [[UILabel alloc] init];
    [self.view addSubview:setLab];
    setLab.numberOfLines = 0;
    setLab.textColor = [UIColor dc_colorWithHexString:@"#000000" alpha:0.8];
    setLab.font = PFRFontMedium(13);
    NSString *titleStr = @"开机状态下，长按上图所示按钮“7秒”，直到“滴”长 响一声，面板wifi指示灯闪烁状态";
    NSMutableAttributedString *attribut = [[NSMutableAttributedString alloc] initWithString:titleStr];
    [attribut addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#4677EE"]} range:[titleStr rangeOfString:@"7秒"]];
    setLab.attributedText = attribut;
    [setLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(27);
        make.right.offset(-26);
        make.top.mas_equalTo(noticeIcon.mas_bottom).offset(65);
    }];
    
    MJWeakSelf;
    self.nextLab = [[UILabel alloc] init];
    [self.view addSubview:self.nextLab];
    self.nextLab.backgroundColor = [UIColor colorWithHexString:@"#F1F1F1"];
    self.nextLab.userInteractionEnabled = NO;
    self.nextLab.textColor = [UIColor dc_colorWithHexString:@"#000000" alpha:0.2];
    self.nextLab.text = @"下一步";
    self.nextLab.font = PFRFontMedium(16);
    self.nextLab.textAlignment = NSTextAlignmentCenter;
    self.nextLab.layer.cornerRadius = 24;
    self.nextLab.layer.masksToBounds = YES;
    [self.nextLab addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [weakSelf nextStep];
    }]];
    
    [self.nextLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(14);
        make.right.offset(-14);
        make.height.mas_equalTo(48);
        make.bottom.offset(-50);
    }];
    
    UILabel *tipLab = [[UILabel alloc] init];
    [self.view addSubview:tipLab];
    tipLab.font = PFRFont(14);
    tipLab.textColor = [UIColor dc_colorWithHexString:@"#000000" alpha:0.8];
    tipLab.text = @"已确认上述操作";
    [tipLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.bottom.mas_equalTo(self.nextLab.mas_top).offset(-24);
    }];
    
    self.sureImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"add_unselect"]];
    self.sureImageV.userInteractionEnabled = YES;
    [self.view addSubview:self.sureImageV];
    [self.sureImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(19);
        make.centerY.mas_equalTo(tipLab);
        make.right.mas_equalTo(tipLab.mas_left).offset(-9);
    }];
    [self.sureImageV addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [weakSelf clickSureImage];
    }]];
}

- (void)nextStep {
    
    MXAddSetWifiController *wifiVC = [[MXAddSetWifiController alloc] init];
    wifiVC.familyId = self.familyId;
    wifiVC.categoryId = self.categoryId;
    [self.navigationController pushViewController:wifiVC animated:YES];
}

- (void)clickSureImage{
    self.select = !self.select;
    if (self.select) {
        self.sureImageV.image = [UIImage imageNamed:@"add_select"];
        self.nextLab.backgroundColor = [UIColor colorWithHexString:@"#3278F6"];
        self.nextLab.userInteractionEnabled = YES;
        self.nextLab.textColor = [UIColor whiteColor];
    } else {
        self.sureImageV.image = [UIImage imageNamed:@"add_unselect"];
        self.nextLab.backgroundColor = [UIColor colorWithHexString:@"#F1F1F1"];
        self.nextLab.userInteractionEnabled = NO;
        self.nextLab.textColor = [UIColor dc_colorWithHexString:@"#000000" alpha:0.2];
    }
}

- (void)leftTap {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self dc_navBarHidden:YES];
}

@end
